package com.sms.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.sms.common.A;
import com.sms.pojo.Promotions;
import com.sms.service.impl.PromotionsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//优惠修改
@WebServlet("/PromotionsModify")
public class PromotionsModifyController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletInputStream inputStream = req.getInputStream();
        String s = IoUtil.readUtf8(inputStream);
        JSONObject obj = JSONUtil.parseObj(s);
        Promotions m=new Promotions();
        BeanUtil.copyProperties(obj,m);
        PromotionsServiceImpl service=new PromotionsServiceImpl();
        service.updateById(m);
        service.getSqlSession().close();
        resp.getWriter().write(JSONUtil.toJsonStr(A.success("修改成功")));
    }
}
